package com.ruiaa.meeting.utils;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.ruiaa.meeting.common.Constant;
import com.ruiaa.meeting.model.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author chenhuaiyi
 * @date 2022-11-04 20:56
 */
@Component
public class StpAuthorizeUtil implements StpInterface {
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return null;
    }

    /**
     *
     * @param loginId 登录id,即usernanme
     * @param loginType
     * @return 返回角色列表 USER ADMIN SUPER_ADMIN
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        // 获取session中的用户
        User user = (User) StpUtil.getSession().get((String) loginId);
        List<String> roles = Collections.synchronizedList(new ArrayList<>());
        String role = user.getRole();

        switch (role){
            case Constant.Role.SUPER_ADMIN: roles.add(Constant.Role.SUPER_ADMIN);
            case Constant.Role.ADMIN: roles.add(Constant.Role.ADMIN);
            case Constant.Role.USER: roles.add(Constant.Role.USER);
        }
        return roles;
    }
}
